package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.data.properties.ConfigProperties;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.properties.ImageProperties;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author chenqiwen
 * @CreateDate: 2021-10-19-16-56
 * @Description:
 */
@RestController
@RequestMapping("/api/config")
public class ConfigController extends BaseController {

    @Autowired
    private UserService userService;
    @Autowired
    private ConfigProperties configProperties;
    @Autowired
    private ImageProperties imageProperties;

    @GetMapping("/findBackEndUrl")
    public ServerResponse findBackEndUrl(HttpServletRequest request, String type) {
        UserInfo userInfo = userService.getLoginUserInfo(request);

        Map<String, String> map = new HashMap<>();
        if ("admin".equals(type)){
            map.put("url", configProperties.getAdminBackEndUrl());
        } else if ("wap".equals(type)){
            map.put("url", configProperties.getWapBackEndUrl());
        } else if ("image".equals(type)){
            map.put("url", imageProperties.getBaseUrl());
        } else if("ws".equals(type)){
            map.put("url", configProperties.getWsAdminBackEndUrl());
        }
        else {
            return ServerResponse.createByErrorMessage("类型有误");
        }

        return ServerResponse.createBySuccess(map);
    }
}
